home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7893 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: realloc(NULL,100)
  5. Date: 28 Feb 1996 22:18:25 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb28151825@qcd.lanl.gov>
  8. References: <31346CB0.41C67EA6@jupiter.di.uminho.pt>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: Rui Bastos's message of Wed, 28 Feb 1996 14:54:40 +0000
  13.  
  14. In article <31346CB0.41C67EA6@jupiter.di.uminho.pt>
  15. Rui Bastos <rui@jupiter.di.uminho.pt> writes:
  16.  
  17. RB: Hi,
  18. RB: 
  19. RB:    Does anybody knows what's the expected behaviour of this program?
  20.  
  21. There is no expected behaviour from a program that invokes undefined
  22. behaviour. 
  23.  
  24. RB: 
  25. RB: #include <stdio.h>
  26. RB: #include <malloc.h>
  27.  
  28. There is no such header in standard C. realloc is declared in
  29. <stdlib.h>. If you include <malloc.h>, the behaviour is undefined.
  30.  
  31. RB:  
  32. RB: main()
  33. RB: {
  34. RB:    void *x=NULL;
  35. RB:    x=realloc(NULL,100);
  36.  
  37. If you had included <stdlib.h> instead, then this call is equivalent
  38. to calling malloc(100).
  39.  
  40. RB:    printf("%p\n",x);
  41. RB: }
  42. RB: 
  43. RB:   I tested it under diferent compilers/operating systems
  44. RB: and  it returns null, others returns a valid address and other
  45. RB: crashes.
  46.  
  47. Except for the undefined behaviour, returning null or a valid address
  48. are both correct behaviours. Crashing is not.
  49.  
  50. Cheers
  51. Tanmoy
  52. --
  53. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  54. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  55. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  56. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  57. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  58. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  59.